package main.java.view;

import java.awt.Color;
import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

import main.java.model.Lights;

public class ButtonsView extends JPanel implements Observer {
    
    //static final variables of view dimension to modify them easier
    private static final int SIZE1 = 90;
    private static final int SIZE2 = 180;
    
    private JButton handleButtonDown;
    private JButton handleButtonUp;
    
    /**
     * Constructor ButtonsView
     */
    public ButtonsView() {
        //Instantiation of the buttons
        handleButtonDown = new JButton("Handle Down");
        handleButtonUp = new JButton("Handle Up");
        
        //Initialize panel info
        handleButtonDown.setPreferredSize(new Dimension(SIZE2, SIZE1));
        handleButtonUp.setPreferredSize(new Dimension(SIZE2, SIZE1));
        handleButtonUp.setEnabled(false);
        
        //Adding items to the view
        this.add(handleButtonUp);
        this.add(handleButtonDown);
        this.setBackground(Color.white);
        this.setPreferredSize(new Dimension(SIZE2, SIZE2));
    }
    
    /**
     * Update calling another function 
     * Depending on the lights
     * @param Observable : what type of instance
     * @param Object : given change 
     */
    @Override
    public void update(Observable arg0, Object arg1) {
        if (arg0 instanceof Lights && arg1.toString() == "Red") {
            manually();
        }
    }

    /**
     * Switch button when an error happens
     */
    public void manually() {
        handleButtonDown.setText("Manual Activation");
        handleButtonDown.setBorder(new LineBorder(Color.red));
        handleButtonDown.setEnabled(true);
    }
    
    /**
     * Switch button to handle the error manually
     */
    public void manualActionButton() {
        handleButtonDown.setText("Handle Switch");
        handleButtonDown.setBorder(new JButton().getBorder());
        handleButtonDown.setEnabled(false);
    }
    
    public JButton getHandleButtonUp() {
        return handleButtonDown;
    }

    public void setHandleButtonUp(JButton handleButtonUp) {
        this.handleButtonDown = handleButtonUp;
    }

    public JButton getHandleButtonDown() {
        return handleButtonUp;
    }

    public void setHandleButtonDown(JButton handleButtonDown) {
        this.handleButtonUp = handleButtonDown;
    }
}
